<?php

namespace App\Console\Commands\Shop;

use App\Kuafu\WaiMai\Enum\WaiMaiDBEnum;
use App\Kuafu\WaiMai\Model\WaiMaiShopMappingModel;
use Illuminate\Console\Command;

class InitDouyinWaimaiShop extends Command
{

    protected $signature = 'shop:initDouyinWaimaiShop';

    protected $description = '初始化抖音外卖三方店铺绑定和抖音团购thirdShopId一样';


    public function handle()
    {
        WaiMaiShopMappingModel::query()
                              ->where("sourceType", WaiMaiDBEnum::SOURCE_TYPE_DOUYIN)
                              ->chunkById(100, function ($item) {
                                  foreach ($item as $waiMaiShop) {
                                      if ($waiMaiShop) {

                                          // 抖音外卖
                                          $res = WaiMaiShopMappingModel::addData(
                                              WaiMaiDBEnum::SOURCE_TYPE_DOUYIN_WM,
                                              (int)$waiMaiShop->shopId,
                                              (string)$waiMaiShop->thirdShopId,
                                              (string)$waiMaiShop->thirdShopName
                                          );

                                          $this->info(vsprintf('shopId [%s] thirdShopId [%s] thirdShopName [%s] 结果 [%s]',
                                              [
                                                  $waiMaiShop->shopId,
                                                  $waiMaiShop->thirdShopId,
                                                  $waiMaiShop->thirdShopName,
                                                  $res,
                                              ]));
                                      }
                                  }
                              });
    }

}
